//
//  ProfileView.swift
//  GFQM
//
//  Created by iSolar on 2017/4/21.
//  Copyright © 2017年 iSolar. All rights reserved.
//

import UIKit

class ProfileView: UIView {
    
    lazy var headView: UIView = UIView()
    lazy var contentView: UIView = UIView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupHeadView()
        setupContentView()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

extension ProfileView {
    fileprivate func setupHeadView() {
        addSubview(headView)
        headView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 170)
        let topView = UIView()
        topView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 60)
        
        let icon = UIImageView()
        icon.frame = CGRect(x: 20, y: 15, width: 40, height: 40)
        icon.image = UIImage(named:"icon")
        icon.layer.cornerRadius = 20
        icon.layer.masksToBounds = true
        
        let nickNameL = UILabel()
        nickNameL.frame = CGRect(x: 80, y: 15, width: UIScreen.main.bounds.width-180, height: 20)
        nickNameL.font = UIFont.systemFont(ofSize: 15)
        nickNameL.text = "行走的僵尸"
        nickNameL.textColor = UIColor.black
        nickNameL.textAlignment = .left
        
        let presentV = UIImageView()
        presentV.frame = CGRect(x: 80, y: 40, width: 15, height: 15)
        presentV.image = UIImage(named:"礼物")
        
        let signL = UILabel()
        signL.frame = CGRect(x: 105, y: 37, width: 50, height: 20)
        signL.font = UIFont.systemFont(ofSize: 12)
        signL.textAlignment = .left
        signL.text = "签到"
        signL.textColor = UIColor.orange
        
        let arrowV = UIImageView()
        arrowV.frame = CGRect(x: UIScreen.main.bounds.width-40, y: 22, width: 15, height: 15)
        arrowV.image = UIImage(named:"arrow")
        
        let vipL = UILabel()
        vipL.frame = CGRect(x: UIScreen.main.bounds.width-120, y: 22, width: 80, height: 20)
        vipL.textColor = UIColor.lightGray
        vipL.font = UIFont.systemFont(ofSize: 13)
        vipL.textAlignment = .right
        vipL.text = "开通豪华VIP"
        
        let vipV = UIImageView()
        vipV.frame = CGRect(x: UIScreen.main.bounds.width-140, y: 22, width: 20, height: 20)
        vipV.image = UIImage(named:"VIP")
        
        headView.addSubview(topView)
        topView.addSubview(icon)
        topView.addSubview(nickNameL)
        topView.addSubview(presentV)
        topView.addSubview(signL)
        topView.addSubview(arrowV)
        topView.addSubview(vipL)
        topView.addSubview(vipV)
        
        let btnViews = UIView()
        btnViews.frame = CGRect(x: 0, y: 70, width: UIScreen.main.bounds.width, height: 100)
        headView.addSubview(btnViews)
        headView.backgroundColor = UIColor.white
        var imageArr = NSArray()
        var titleArr = NSArray()
        var numArr = NSArray()
        
        imageArr = ["歌曲","下载","最近播放","喜欢"]
        titleArr = ["本地歌曲","我的下载","最近播放","我喜欢听"]
        numArr = ["146","146","125","16"]
        for index in 0..<imageArr.count {
            let btnView = UIView()
            btnView.frame = CGRect(x: UIScreen.main.bounds.width/4*CGFloat(index), y: 0, width: UIScreen.main.bounds.width, height: 100)
            btnViews.addSubview(btnView)
            let imgV = UIImageView()
            imgV.frame = CGRect(x: (UIScreen.main.bounds.width/4-40)/2, y: 0, width: 40, height: 40)
            imgV.image = UIImage(named:imageArr[index] as! String)
            btnView.addSubview(imgV)
            let titleL = UILabel()
            titleL.frame = CGRect(x: 0, y: 50, width: UIScreen.main.bounds.width/4, height: 20)
            titleL.text = titleArr[index] as? String
            titleL.font = UIFont.systemFont(ofSize: 13)
            titleL.textAlignment = .center
            titleL.textColor = UIColor.black
            btnView.addSubview(titleL)
            let numL = UILabel()
            numL.frame = CGRect(x: 0, y: 70, width: UIScreen.main.bounds.width/4, height: 20)
            numL.text = numArr[index] as? String
            numL.textAlignment = .center
            numL.textColor = UIColor.lightGray
            numL.font = UIFont.systemFont(ofSize: 12)
            btnView.addSubview(numL)
            let btn = UIButton()
            btn.frame = btnView.frame
            btnViews.insertSubview(btn, aboveSubview: btnView)
            btn.tag = index + 1
            btn.addTarget(self, action: #selector(ProfileView.btnClick(_ :)), for: .touchUpInside)
        }
        
    }
    
    fileprivate func setupContentView(){
        addSubview(contentView)
        contentView.backgroundColor = UIColor.white
        contentView.frame = CGRect(x: 0, y: 180, width: UIScreen.main.bounds.width, height: 241)
        let listL = UILabel()
        listL.frame = CGRect(x: 15, y: 0, width: 90, height: 39)
        listL.textColor = UIColor.black
        listL.text = "自建歌单(0)"
        listL.font = UIFont.systemFont(ofSize: 15)
        contentView.addSubview(listL)
        let arrowBtn = UIButton()
        arrowBtn.frame = CGRect(x: UIScreen.main.bounds.width-35, y: 12, width: 20, height: 15)
        arrowBtn.setImage(UIImage(named:"下拉"), for: .normal)
        contentView.addSubview(arrowBtn)
        let listBtn = UIButton()
        listBtn.frame = CGRect(x: UIScreen.main.bounds.width-80, y: 10, width: 20, height: 20)
        listBtn.setImage(UIImage(named:"自建列表"), for: .normal)
        contentView.addSubview(listBtn)
        let addBtn = UIButton()
        addBtn.frame = CGRect(x: UIScreen.main.bounds.width-125, y: 10, width: 20, height: 20)
        addBtn.setImage(UIImage(named:"加号"), for: .normal)
        contentView.addSubview(addBtn)
        
        let lineV = UIImageView()
        lineV.frame = CGRect(x: 0, y: 39, width: UIScreen.main.bounds.width, height: 1)
        lineV.image = UIImage(named:"userLine")
        contentView.addSubview(lineV)
        
        let view = UIImageView()
        view.frame = CGRect(x: 15, y: 50, width: 50, height: 50)
        view.image = UIImage(named:"viewBg")
        contentView.addSubview(view)
        let imgV = UIImageView()
        imgV.frame = CGRect(x: 15, y: 15, width: 20, height: 20)
        imgV.image = UIImage(named:"新建")
        view.addSubview(imgV)
        
        let label = UILabel()
        label.frame = CGRect(x: 75, y: 65, width: 80, height: 20)
        label.font = UIFont.systemFont(ofSize: 15)
        label.text = "新建歌单"
        label.textColor = UIColor.black
        contentView.addSubview(label)
        
        let lineV2 = UIImageView()
        lineV2.frame = CGRect(x: 0, y: 109, width: UIScreen.main.bounds.width, height: 1)
        lineV2.image = UIImage(named:"userLine")
        contentView.addSubview(lineV2)
        
        let titleLabel = UILabel()
        titleLabel.frame = CGRect(x: 15, y: 110, width: 100, height: 40)
        titleLabel.text = "收藏歌单(0)"
        titleLabel.font = UIFont.systemFont(ofSize: 15)
        titleLabel.textColor = UIColor.black
        contentView.addSubview(titleLabel)
        
        let arrowBtn2 = UIButton()
        arrowBtn2.frame = CGRect(x: UIScreen.main.bounds.width-35, y: 122, width: 20, height: 15)
        arrowBtn2.setImage(UIImage(named:"下拉"), for: .normal)
        contentView.addSubview(arrowBtn2)
        
        let bgV = UIImageView()
        bgV.frame = CGRect(x: 0, y: 150, width: UIScreen.main.bounds.width, height: 10)
        bgV.image = UIImage(named:"userLine")
        contentView.addSubview(bgV)
        
        let img1 = UIImageView()
        img1.frame = CGRect(x: 15, y: 170, width: 20, height: 20)
        img1.image = UIImage(named:"直播")
        contentView.addSubview(img1)
        
        let la1 = UILabel()
        la1.frame = CGRect(x: 45, y: 170, width: 40, height: 20)
        la1.textColor = UIColor.black
        la1.text = "直播"
        la1.font = UIFont.systemFont(ofSize: 15)
        contentView.addSubview(la1)
        
        let la2 = UILabel()
        la2.frame = CGRect(x: 80, y: 170, width: UIScreen.main.bounds.width-115, height: 20)
        la2.textColor = UIColor.lightGray
        la2.textAlignment = .right
        la2.text = "耳膜被震，这么唱好么？"
        la2.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(la2)
        
        let img2 = UIImageView()
        img2.frame = CGRect(x: UIScreen.main.bounds.width-35, y: 172, width: 20, height: 15)
        img2.image = UIImage(named:"arrow")
        contentView.addSubview(img2)

        let bgV2 = UIImageView()
        bgV2.frame = CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 1)
        bgV2.image = UIImage(named:"userLine")
        contentView.addSubview(bgV2)
        let img3 = UIImageView()
        img3.frame = CGRect(x: 15, y: 210, width: 20, height: 20)
        img3.image = UIImage(named:"发现")
        contentView.addSubview(img3)
        
        let la3 = UILabel()
        la3.frame = CGRect(x: 45, y: 210, width: 40, height: 20)
        la3.textColor = UIColor.black
        la3.text = "发现"
        la3.font = UIFont.systemFont(ofSize: 15)
        contentView.addSubview(la3)
        
        let la4 = UILabel()
        la4.frame = CGRect(x: 80, y: 210, width: UIScreen.main.bounds.width-115, height: 20)
        la4.textColor = UIColor.lightGray
        la4.textAlignment = .right
        la4.text = "重低音 超乎你的想象【酷我无线耳机】"
        la4.font = UIFont.systemFont(ofSize: 12)
        contentView.addSubview(la4)
        
        let img4 = UIImageView()
        img4.frame = CGRect(x: UIScreen.main.bounds.width-35, y: 212, width: 20, height: 15)
        img4.image = UIImage(named:"arrow")
        contentView.addSubview(img4)

    }
}

extension ProfileView {
    @objc fileprivate func btnClick (_ sender:UIButton){

        debugPrint(sender.tag)
        switch sender.tag {
        case 1:
            
            break
        case 2:
            
            break
        case 3:
            
            break
        case 4:
            
            break
        default:
            
            break
            
        }
    }
}


